package huixue.cn.com.rxapp.user.present;

import java.util.List;

import huixue.cn.com.library.observer.SimpleObserver;
import huixue.cn.com.rxapp.base.BasePresent;
import huixue.cn.com.rxapp.base.IBaseUI;
import huixue.cn.com.rxapp.api.RetrofitService;
import huixue.cn.com.rxapp.base.BaseActivity;
import huixue.cn.com.rxapp.entity.Gank;
import huixue.cn.com.rxapp.entity.HttpResult;
import huixue.cn.com.rxapp.util.HttpUiTips;

/**
 * Created by gongdongyang on 2018/7/27.
 */

public class IndexPresent extends BasePresent<IndexPresent.IndexUI> {
    //private BaseActivity baseActivity;
    //private IndexUI indexUI;
    public interface IndexUI extends IBaseUI{
        void loadImageSuccess(HttpResult<List<Gank>> listHttpResult);
        void onFail();
    }

    /*public IndexPresent(BaseActivity baseActivity,IndexUI indexUI) {
        this.baseActivity = baseActivity;
        this.indexUI = indexUI;
    }*/

    public void loadData(){
        HttpUiTips.showDialog(getActivity(),true, "loading...");
        RetrofitService.getNewsList("福利", 0).subscribe(new SimpleObserver<HttpResult<List<Gank>>>(){
            @Override
            public void onNext(HttpResult<List<Gank>> listHttpResult) {
                super.onNext(listHttpResult);
                HttpUiTips.dismissDialog(getActivity());
                getmUI().loadImageSuccess(listHttpResult);

            }
            @Override
            public void onError(Throwable e) {
                HttpUiTips.dismissDialog(getActivity());
                getmUI().onFail();
            }
        });
    }
}
